//
//  Bottle_PlayerSelected.m
//  PartyGame
//
//  Created by Peteo on 11-9-4.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Bottle_PlayerSelected.h"
#import "AppController.h"

@implementation Bottle_PlayerSelected

-(void)Bottle_PlayerSelected_Play:(id)sender
{
	if(delegate)
	{
		[delegate Bottle_PlayerSelected:EBottle_PlayerSelected_Play PlayerNum:0];
	}
}

-(void)Bottle_PlayerSelected_Des:(id)sender
{
	if(delegate)
	{
		//AppController * app = (AppController*)[[UIApplication sharedApplication] delegate];
		
		//[app setTextFieldArrayVisable:YES];
		
		[delegate Bottle_PlayerSelected:EBottle_PlayerSelected_Des PlayerNum:0];
	}
}

-(void)Bottle_PlayerSelected_Return:(id)sender
{
	if(delegate)
	{
		[delegate Bottle_PlayerSelected:EBottle_PlayerSelected_Return PlayerNum:0];
	}
}

-(void)Bottle_add_num:(id)sender
{
	AppController * app = (AppController*)[[UIApplication sharedApplication] delegate];
	[app TipSound];
	
	if (app.nBottle_PlayerNum < 8)
	{
		app.nBottle_PlayerNum ++;
	}
	
	[m_pLabelPlayer setString:[NSString stringWithFormat:@"%d 人",app.nBottle_PlayerNum]];
}

-(void)Bottle_remove_num:(id)sender
{
	AppController * app = (AppController*)[[UIApplication sharedApplication] delegate];
	[app TipSound];
	
	if (app.nBottle_PlayerNum > 2)
	{
		app.nBottle_PlayerNum --;
	}
	
	[m_pLabelPlayer setString:[NSString stringWithFormat:@"%d 人",app.nBottle_PlayerNum]];
}

+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	
	// 'layer' is an autorelease object.
	Bottle_PlayerSelected *layer = [Bottle_PlayerSelected node];
	
	// add layer as a child to scene
	[scene addChild: layer];
	
	// return the scene
	return scene;
}

-(id)init:(id<Bottle_PlayerSelectedDelegate>) _delegate
{
	self = [super init];
	if (self)
	{
		AppController * app = (AppController*)[[UIApplication sharedApplication] delegate];
		
		delegate = _delegate;
		
		CGSize size = [[CCDirector sharedDirector] winSize];
	
		//LOGO
		CCSprite *spLogo=[CCSprite spriteWithFile:@"logo2.png"];
		spLogo.position = ccp(SCREEN_WIDTH/2,460);
		[self addChild:spLogo];
		
		CCSprite *spTitle=[CCSprite spriteWithFile:@"游戏人数.png"];
		spTitle.position=ccp(size.width/2 , 300);
		[self addChild:spTitle];
		
		//玩家人数背景
		CCSprite *numBg=[CCSprite spriteWithFile:@"num_bg.png"];
		numBg.position = ccp(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
		[self addChild:numBg];
		
		m_pLabelPlayer = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%d 人",app.nBottle_PlayerNum] 
										 fontName:@"Helvetica-Bold" 
										 fontSize:24];
		m_pLabelPlayer.color = ccc3(96,121,143);
		//m_pLabelPlayer.color = ccBLUE;
		m_pLabelPlayer.position =  ccp( SCREEN_WIDTH/2 ,SCREEN_HEIGHT/2);
		[self addChild:m_pLabelPlayer];
		
		
		CCMenuItem *addMenu = [CCMenuItemImage itemFromNormalImage:@"bottle_add.png"
													   selectedImage:nil 
															  target:self 
															selector:@selector(Bottle_add_num:)];
	
		CCMenu *menuadd = [CCMenu menuWithItems:addMenu, nil];
		menuadd.position = ccp(SCREEN_WIDTH/2 - 90,SCREEN_HEIGHT/2);
		[self addChild:menuadd];
		
		CCMenuItem *removeMenu = [CCMenuItemImage itemFromNormalImage:@"bottle_remove.png"
													 selectedImage:nil 
															target:self 
														  selector:@selector(Bottle_remove_num:)];
		
		CCMenu *menuremove = [CCMenu menuWithItems:removeMenu, nil];
		menuremove.position = ccp(SCREEN_WIDTH/2 + 90,SCREEN_HEIGHT/2);
		[self addChild:menuremove];
		
		
		//底部背景
		CCSprite *bottomBg=[CCSprite spriteWithFile:@"bottom_bg.png"];
		bottomBg.position = ccp(SCREEN_WIDTH/2,BOTTOM_HEIGHT);
		[self addChild:bottomBg];
		
		//开始
		CCMenuItem *startMenu = [CCMenuItemImage itemFromNormalImage:@"btn_start.png" 
													   selectedImage:@"btn_start_down.png" 
															  target:self 
															selector:@selector(Bottle_PlayerSelected_Play:)];
		startMenu.position = ccp(size.width/2,BOTTOM_HEIGHT);
		CCMenu *menuCardBack = [CCMenu menuWithItems:startMenu, nil];
		menuCardBack.position = CGPointZero;
		[self addChild:menuCardBack];
		
		//返回
		CCMenuItemImage *vm = [CCMenuItemImage itemFromNormalImage:@"back_icon.png" selectedImage:nil target:self selector:@selector(Bottle_PlayerSelected_Return:)];	
		CCMenu *vmm = [CCMenu menuWithItems: vm, nil];
		vmm.position = ccp(BOTTOM_X, BOTTOM_HEIGHT);
		[self addChild:vmm z:2];
		
		//help
		
		CCMenuItemImage *help = [CCMenuItemImage itemFromNormalImage:@"help_icon.png" selectedImage:nil target:self selector:@selector(Bottle_PlayerSelected_Des:)];	
		CCMenu *helpMenu = [CCMenu menuWithItems: help, nil];
		helpMenu.position = ccp(SCREEN_WIDTH - BOTTOM_X , BOTTOM_HEIGHT);
		[self addChild:helpMenu z:2];
	}
	
	return self;
}


- (void)layerReplaced
{
	
}

@end
